﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using AutoGear.BLL;
using ECommerce.Library.DataStructure;
using ECommerce.Library.Web;
using System.Collections.Generic;
using ECommerce.Library;
using System.IO;

public partial class admin_newsletter_template_details : SiteAdminBasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //SessionManager.CurrentAdminPage = AdminPageName.NewsletterTemplateDetails;
        if (!IsPostBack)
        {
            BindInfo();
        }

    }

    private void BindInfo()
    {
        //if (CurrentPageMode == PageLoadMode.Add)
        //{
        //    txtTemplateName.Text = "";
        //    fckeTemplateDesign.Value = "";
        //    return;
        //}
        //if (CurrentPageMode == PageLoadMode.Edit)
        //{
            Entity.TblEmailTemplate newsletterTemplate = Entity.TblEmailTemplate.GetTblEmailTemplateByEmailTemplateId(NewsletterTemplateId);
            txtTemplateId.Text = newsletterTemplate.EmailTemplateId.ToString();
            txtTemplateName.Text = newsletterTemplate.EmailSubject;
            fckeTemplateDesign.Value = newsletterTemplate.EmailBody;
            return;
        //}
    }

    protected void btnSave_Click(object sender, EventArgs e)
    {
        Entity.TblEmailTemplate iNewsletterTemplate = Entity.TblEmailTemplate.GetTblEmailTemplateByEmailTemplateId(Convert.ToInt32(txtTemplateId.Text));
        iNewsletterTemplate.EmailSubject = txtTemplateName.Text;
        iNewsletterTemplate.EmailBody = fckeTemplateDesign.Value;

        if (iNewsletterTemplate.Save())
        {
                lblCRUDMessege.Text = "Operation Successful.";
                lblCRUDMessege.CssClass = "message";
        }
        else
        {
            lblCRUDMessege.Text = "Operation Not Successful.";
            lblCRUDMessege.CssClass = "errorMessage";
        }
        BindInfo();
    }

    private int NewsletterTemplateId
    {
        get
        {
            if (string.IsNullOrEmpty(Request.QueryString["id"]))
                return 0;
            return Convert.ToInt32(Request.QueryString["id"]);
        }
    }

    //private PageLoadMode CurrentPageMode
    //{
    //    get
    //    {
    //        if (NewsletterTemplateId > 0)
    //            return PageLoadMode.Edit;
    //        return PageLoadMode.Add;
    //    }
    //}
}
